const { desktopCapturer } = require('electron')
// const { sendControlWin } = require('../')

// 桌面id
async function getScreenId() {
    const sources = await desktopCapturer.getSources({ types: ['screen'] })
    const sourceId = sources[0].id
    return sourceId
}

// 获取桌面流
async function getStream(sourceId) {
    try {
        const stream = await navigator.mediaDevices.getUserMedia({
          audio: false,
          video: {
            mandatory: {
              chromeMediaSource: 'desktop',
              chromeMediaSourceId: sourceId,
              minWidth: 1280,
              maxWidth: 1280,
              minHeight: 720,
              maxHeight: 720
            }
          }
        })
        return stream
    } catch (e) {
        console.log(e)
    }
}

module.exports = {
    getScreenId,
    getStream
}
